package com.tbq.game.service.app

import android.app.Activity
import android.app.Application
import android.content.Context
import androidx.core.app.NotificationCompat
import com.tbq.game.service.http.JsonConverter
import com.tbq.game.service.http.LoggerInterceptor
import com.yanzhenjie.kalle.Kalle
import com.yanzhenjie.kalle.KalleConfig
import java.util.*

class App : Application() {
    var activities: LinkedList<Activity> = LinkedList()
    companion object {
        var context: App? = null
     //   var user: User? = null
        var mNetWorkState: Int = 0
        var builder: NotificationCompat.Builder? = null

    }

    override fun onCreate() {
        super.onCreate()
       Kalle.setConfig(KalleConfig.newBuilder().converter(JsonConverter()).addInterceptor(LoggerInterceptor()).build())
    }
    fun addActivity(activity: Activity) {
        if (!activities.contains(activity)) {
            activities.add(activity)
        }
    }

    /**
     * 移除Activity引用
     */
    fun removeActivity(activity: Activity) {
        activities.remove(activity)
    }

    /**
     * 退出APP
     */
    fun exitApp() {
        try {
            activities.forEach { it.finish() }
        } catch (e: Exception) {
            e.printStackTrace()
        } finally {
            System.exit(0)
            android.os.Process.killProcess(android.os.Process.myPid())
            System.exit(0)
        }
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
       // MultiDex.install(this)
    }
}